const bestScoreStorageKey = 'BestScore';
export class GameDataModel{
    private static instance: GameDataModel = new GameDataModel();

    private curScore: number = 0;

    public static getInstance(): GameDataModel{
        return this.instance;
    }

    public addScore(score: number): void{
        this.curScore += score;
    }

    public getScore(): number{
        return this.curScore;
    }

    public getBestScore(): number{
        let result = cc.sys.localStorage.getItem(bestScoreStorageKey);
        return result == null ? 0 : result as number;
    }

    public saveScore(): void{
        if(this.curScore > this.getBestScore()){
            cc.sys.localStorage.setItem(bestScoreStorageKey, this.curScore);
        }
    }

    public clearScore(): void{
        this.curScore = 0;
    }
}